package club.beimeng.demos.demo2021年5月18日;

import java.util.*;
class Three{
    static int n = 0;
    static void isPrime(int n){

        for(int i = 2; i <= n / i; ++i){
            int cnt = 0;
            while(n % i == 0){
                n /= i;
                cnt++;
            }
            if(cnt != 0)System.out.println(i + " " + cnt);
        }
        if(n > 1)System.out.println(n + " " + "1");
        System.out.println();
    }
    public static void main(String[] args)throws Exception{
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        while(n -- != 0){
            int a = sc.nextInt();
            isPrime(a);
        }
    }
}

/*
 *
 * @author Mr.Bao
 * @date
 */